import request from '@/utils/request'
const qs = require("qs")
export function login(data,loginType) {
  let params = {}
  if (loginType == "phone") {
    params = {
      code: data.phoneCode,
      phoneNumber: data.phoneNumber,
      loginType
    }
  } else {
    params = {
      username: data.username,
      password: data.password,
      loginType
    }
  }
  // console.log(params)
  // return 
  return request({
    url: '/admin/login',
    method: 'post',
    data: params
  })
}

export function getPhoneCode (phoneNumber) {
  return request ({
    url: '/admin/sendLoginCode',
    method: 'post',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    data: qs.stringify({phoneNumber})
  })
}

export function getInfo() {
  return request({
    url: '/admin/info',
    method: 'get',
  })
}

export function getMenus() {
  return request({
    url: '/admin/menus',
    method: 'get',
  })
}


export function logout() {
  return request({
    url: '/admin/logout',
    method: 'get'
  })
}

export function fetchList(params) {
  return request({
    url: '/admin/list',
    method: 'get',
    params: params
  })
}

export function createAdmin(data) {
  return request({
    url: '/admin/register',
    method: 'post',
    data: data
  })
}

export function updateAdmin(id, data) {
  return request({
    url: '/admin/update/' + id,
    method: 'post',
    data: data
  })
}

export function updateStatus(id, params) {
  return request({
    url: '/admin/updateStatus/' + id,
    method: 'post',
    params: params
  })
}

export function deleteAdmin(id) {
  return request({
    url: '/admin/delete/' + id,
    method: 'post'
  })
}

export function getRoleByAdmin(id) {
  return request({
    url: '/admin/role/' + id,
    method: 'get'
  })
}

export function allocRole(data) {
  return request({
    url: '/admin/role/update',
    method: 'post',
    data: data
  })
}
export function getUserInfo(id) {
    return request({
      url:'/admin/' + id,
      method: 'get',
    })
}

export function editUserInfo(id, data) {
  return request({
    url: '/admin/update/' + id,
    method: 'post',
    data
  })
}
